package ft;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class T2 {

    public static int num = 0;
    public static final Lock lock = new ReentrantLock();

    public static void main(String[] args) {
        Thread t1 = new Thread(task);
        Thread t2 = new Thread(task);
        Thread t3 = new Thread(task);
        Thread t4 = new Thread(task);

        for (int i = 0; i < 50; i++) {
            t1.run();
            t2.run();
            t3.run();
            t4.run();
        }

    }

    public static Runnable task = new Runnable() {
        @Override
        public void run() {
            lock.lock();

            System.out.println(num%4 + 1);
            num++;

            lock.unlock();
        }
    };


}
